package com.easpeed.comon.utils

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils


object CommonOperateUtils {


    /**
     * 跳转到指定的Activity
     *
     * @param clazz
     * @param isFinish 是否销毁当前页面
     */
//    @JvmStatic
//    @JvmOverloads
//    fun moveTo(
//        mContext: Context?,
//        clazz: Class<*>?,
//        isFinish: Boolean = false,
//        bundle: Bundle? = null,
//    ) {
//        val intent = Intent(mContext, clazz)
//        bundle?.let {
//            intent.putExtras(bundle)
//        }
//        mContext?.startActivity(intent)
//        if (isFinish) {
//            (mContext as Activity).finish()
//        }
//    }

    /**
     * 跳转到指定的Activity
     *
     * @param clazz
     * @param isFinish 是否销毁当前页面
     */
    @JvmStatic
    @JvmOverloads
    open fun moveTo(
        mContext: Context?,
        clazz: Class<*>?,
        bundle: Bundle? = null,
        requestCode: Int = 0,
    ) {
        val intent = Intent(mContext, clazz)
        bundle?.let {
            intent.putExtras(bundle)
        }
        if (requestCode == 0) {
            mContext?.startActivity(intent)
        } else {
            (mContext as Activity).startActivityForResult(intent, requestCode)
        }
    }


    /**
     * 跳转到指定的Activity
     *
     * @param clazz
     */
    @JvmStatic
    fun moveToClearTask(clazz: Class<*>?, mActivity: Application?) {
        val intent = Intent(mActivity, clazz)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        mActivity?.startActivity(intent)
    }

    @JvmStatic
    fun openWebView(mContext: Context, url: String?) {
        if (TextUtils.isEmpty(url)) {
            return
        }
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
        mContext.startActivity(intent)
    }


    /**
     * 跳转到系统打电话
     */
    @JvmStatic
    fun jumpDial(mContext: Context?, phoneNumber: String?) {
        val intent = Intent(Intent.ACTION_DIAL)
        intent.data = Uri.parse("tel:${phoneNumber}")
        mContext?.startActivity(intent)
    }


}